"""
@name : 1.调试
@author : wenyao
@projectname: sanchuanglianxi
"""
#1、print调试
# def func():
#     data = input('请输入一个数字:')
#     data = int(data)
#     print("data 的值为:",data)
#     return 100/data
#
# print(func())

#ide debug 断点调试
# data = []
# def func1():
#     data.append(1)
# print("断点一")
# func1()
# print("断点二")
# func1()
# print("断点三")


#pdb调试
# def func():
#     b =[]
#     b.append(1)
#     print("pdb start....")
#     import pdb
#     pdb.set_trace()
#     print("pdb end......")
#
# func()

#logging调试

import logging
from logging.handlers import RotatingFileHandler,TimedRotatingFileHandler

#基本配置
# logging.basicConfig(level= logging.DEBUG,
#                     format="%(asctime)s -%(name)s-%(levelno)s: %(message)s")
# logging.info("this is info message")

# #
# logger = logging.getLogger()
# #fh = logging.FileHandler("log/test.log")
# #按照文件大小轮转
# fh = RotatingFileHandler("log/test.log", maxBytes=512, backupCount=2)
# #时间备份
# #fh = TimedRotatingFileHandler("log/test.log",when="D",interval=1,backupCount=7)
# formatter = logging.Formatter("%(asctime)s -%(name)s-%(levelno)s: %(message)s")
# fh.setFormatter(formatter)
# logger.addHandler(fh)

# import time
# def func1(i):
#     for _ in range(2):
#         logger.error(f"{i}---->this is error log")

#线程安全
# from threading import Thread
# if __name__ == "__main__":
#     t_lst = []
#     for i in range(10):
#         t = Thread(target=func1, args = (i,))
#         t.start()
#         t_lst.append(t)
#
#     for t in t_lst:
#         t.join()
#     print("test end")

#非进程安全，多进程同时写入会存在问题
# from multiprocessing import Process
#
# if __name__ == "__main__":
#     p_lst = []
#     for i in range(10):
#         p = Process(target=func1, args=(i,))
#         p.start()
#         p_lst.append(p)
#
#     for p in p_lst:
#         p.join()
#     print("process test end")

#字典配置logging

# import logging.config
#
# #字典中的第一层所有的key是固定的
# logging.config.dictConfig({
#     'version': 1,
#     'disable_existing_loggers': True,
#     'formatters': {
#         'verbose': {
#             'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
#             'datefmt': "%Y-%m-%d %H:%M:%S"
#         },
#         'simple': {
#             'format': '%(levelname)s %(message)s'
#         },
#     },
#     'handlers': {
#         'null': {
#             'level': 'DEBUG',
#             'class': 'logging.NullHandler',
#         },
#         'console': {
#             'level': 'DEBUG',
#             'class': 'logging.StreamHandler',
#             'formatter': 'verbose'
#         },
#         'file': {
#             'level': 'DEBUG',
#             'class': 'logging.handlers.RotatingFileHandler',
#             # 当达到10MB时分割日志
#             'maxBytes': 1024 * 1024 * 10,
#             # 最多保留50份文件
#             'backupCount': 50,
#             # If delay is true,
#             # then file opening is deferred until the first call to emit().
#             'delay': True,
#             'filename': 'logs/mysite.log',
#             'formatter': 'verbose'
#         }
#     },
#     'loggers': {
#         '': {
#             'handlers': ['console'],
#             'level': 'DEBUG',
#         },
#     }
# })
#
# logger = logging.getLogger()
# logger.info("this is dict config  logging test")

#断言
#
# def  func1(a,b):
#     return a + b
#
# assert func1(1,2) ==4

# r = input("please input a number:")
# r = int(r)
# assert r != 0
# result = 100 /r
# print(result)